home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
AMICUS
/
AMICUS04.ADF
/
C
/
creatask.c
< prev
next >
Wrap
C/C++ Source or Header
|
1985-10-30
|
2KB
|
59 lines
#include "exec/types.h"
#include "exec/nodes.h"
#include "exec/lists.h"
#include "exec/memory.h"
#include "exec/interrupts.h"
#include "exec/ports.h"
#include "exec/libraries.h"
#include "exec/tasks.h"
#include "exec/execbase.h"
extern APTR AllocMem();
extern struct Task *FindTask();
/*
* Create a task with given name, priority, and stack size.
* It will use the default exception and trap handlers for now.
*/
struct Task *CreateTask(name, pri, initPC, stackSize)
char *name;
UBYTE pri;
APTR initPC;
ULONG stackSize;
{
struct Task *newTask;
ULONG dataSize = (stackSize & 0xfffffc) + 1;
/*
* This should be broken into two allocations: task of PUBLIC
* and stack of PRIVATE
*/
newTask = AllocMem ((ULONG) sizeof (*newTask) + dataSize,
MEMF_CLEAR |MEMF_PUBLIC);
if (!(ULONG) newTask) {
return ((struct Task *) (0));
}
newTask -> tc_SPLower = (APTR)((long) newTask + (long) sizeof (*newTask));
newTask -> tc_SPUpper = (APTR)(((ULONG)(newTask -> tc_SPLower) + dataSize)
& 0xfffffe);
newTask -> tc_SPReg = (APTR) ((long) (newTask -> tc_SPUpper));
newTask -> tc_Node.ln_Type = NT_TASK;
newTask -> tc_Node.ln_Pri = pri;
newTask -> tc_Node.ln_Name = name;
AddTask (newTask, initPC, 0);
return (newTask);
}
DeleteTask(tc)
struct Task *tc;
{
RemTask (tc); /* does not handle self deletion properly */
FreeMem (tc, (ULONG) (tc -> tc_SPUpper) - (ULONG) tc);
}